  

import { axios } from '@/service/service'
import {
  CodeReq,
  ProcessInstanceListReq,
  BatchDeleteReq,
  SubIdReq,
  TaskReq,
  LongestReq,
  ProcessInstanceReq,
  singleIdReq
} from './types'

// 删除作业流实例
export function delProcessInstance(
  params: singleIdReq,
): any {
  return axios({
    url: `/api-scheduler/processInstance/delProcessInstance`,
    method: 'get',
    params
  })
}

// 查询processInstance列表
export function queryProcessInstanceListPaging(
  params: any,
): any {
  return axios({
    url: `/api-scheduler/processInstance/queryProcessInstances`,
    method: 'get',
    params
  })
}

// 甘特图
export function viewGanttTreeReq(
  params: singleIdReq,
): any {
  return axios({
    url: `/api-scheduler/processInstance/viewGantt`,
    method: 'get',
    params
  })
}

// 作业流实例作业状态
export function taskInstancesState(
  params: singleIdReq,
): any {
  return axios({
    url: `/api-scheduler/processInstance/taskInstancesState`,
    method: 'get',
    params
  })
}

// 查看作业流实例变量
export function viewVariablesReq(
  params: singleIdReq,
): any {
  return axios({
    url: `/api-scheduler/processInstance/viewVariables`,
    method: 'get',
    params
  })
}

// 作业流关系
export function processLineageList(
  params: any,
): any {
  return axios({
    url: `/api-scheduler/processLineage/list`,
    method: 'get',
    params
  })
}





// ---------------------  分割线  -----------------------

// 甘特图
export function viewGanttTree(id: number, code: number): any {
  return axios({
    url: `/projects/${code}/process-instances/${id}/view-gantt`,
    method: 'get'
  })
}

// 查看作业流实例变量
export function viewVariables(id: number, code: number): any {
  return axios({
    url: `/projects/${code}/process-instances/${id}/view-variables`,
    method: 'get'
  })
}



export function batchDeleteProcessInstanceByIds(
  data: BatchDeleteReq,
  code: number
): any {
  return axios({
    url: `/projects/${code}/process-instances/batch-delete`,
    method: 'post',
    data
  })
}

export function queryParentInstanceBySubId(
  params: SubIdReq,
  code: CodeReq
): any {
  return axios({
    url: `/projects/${code}/process-instances/query-parent-by-sub`,
    method: 'get',
    params
  })
}

export function querySubProcessInstanceByTaskCode(
  params: TaskReq,
  code: CodeReq
): any {
  return axios({
    url: `/projects/${code.projectCode}/process-instances/query-sub-by-parent`,
    method: 'get',
    params
  })
}

export function queryTopNLongestRunningProcessInstance(
  params: LongestReq,
  code: CodeReq
): any {
  return axios({
    url: `/projects/${code}/process-instances/top-n`,
    method: 'get',
    params
  })
}

export function queryProcessInstanceById(
  instanceId: number,
  projectCode: number
): any {
  return axios({
    url: `/projects/process-instances/${instanceId}`,
    method: 'get'
  })
}

export function updateProcessInstance(
  data: ProcessInstanceReq,
  id: number,
  code: number
): any {
  return axios({
    url: `/projects/${code}/process-instances/${id}`,
    method: 'put',
    data
  })
}

export function deleteProcessInstanceById(id: number, code: number): any {
  return axios({
    url: `/projects/${code}/process-instances/${id}`,
    method: 'delete'
  })
}

export function queryTaskListByProcessId(id: number, code: number): any {
  return axios({
    url: `/projects/${code}/process-instances/${id}/tasks`,
    method: 'get'
  })
}




